package writeFile;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-06-16
 * Time: 11:06
 */

/*
* 需求：把指定字符串写入到文件当中
* 在try()括号中创建文件，执行完代码块之后会自动把文件资源进行关闭释放*/
public class Main {

    private static String str = "hello";
    private static String filePath = "test1.txt";

    public static void main(String[] args) {

        try (FileOutputStream fileOutputStream = new FileOutputStream(filePath)){
            byte[] bytes = str.getBytes();
            fileOutputStream.write(bytes);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
